import wave
import numpy as np
import struct

# 创建一个简单的测试WAV文件
def create_test_wav(filename, duration=3, sample_rate=16000, frequency=440):
    # 生成正弦波音频数据
    t = np.linspace(0, duration, int(sample_rate * duration), False)
    audio_data = np.sin(2 * np.pi * frequency * t)
    
    # 转换为16位整数
    audio_data = (audio_data * 32767).astype(np.int16)
    
    # 写入WAV文件
    with wave.open(filename, 'w') as wav_file:
        wav_file.setnchannels(1)  # 单声道
        wav_file.setsampwidth(2)  # 16位
        wav_file.setframerate(sample_rate)  # 16kHz采样率
        wav_file.writeframes(audio_data.tobytes())
    
    print(f"创建测试WAV文件: {filename}")
    print(f"采样率: {sample_rate}Hz, 声道: 1, 位深: 16bit, 时长: {duration}秒")

if __name__ == "__main__":
    create_test_wav("test_audio.wav")